<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

	<ui:composition 
	  xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      template="/view/templates/templateLayout.xhtml">
      
      <ui:define name="conteudo">    
      <link rel="stylesheet" type="text/css" href="./estilos.css"/>   	
  	
<h:form id="formManterFormaPagamento" prependId="false">  
	<p:panel id="panelManterCondicaoPagamento" header="Manter FormaPagamento" style="margin-bottom:20px; ">  
	<f:facet name="header">
		<h:outputText value="Manter Condição de Pagamento" styleClass="outputTextTitulo"/>
	</f:facet> 
 	<p:messages id="messagesManterCondPgto" autoUpdate="true" closable="true"/> 
    	<h:panelGrid id="pgCondicaoPagamento" columns="2" style="margin-top:20px; margin-right:10%;">  
            <h:outputLabel value="Código" styleClass="outputLabel"/>  
            <h:outputLabel value="Condição de Pagamento*" styleClass="outputLabel"/>             
            <p:inputText value="#{condicaoPagamentoBean.condicaoPagamento.idCondicaoPagamento}" styleClass="inputId" disabled="true" />  
  			<p:inputText value="#{condicaoPagamentoBean.condicaoPagamento.descricao}" maxlength="40"
  							styleClass="inputDescricao" required="true" requiredMessage="Informe o nome da Condição de Pagamento!"/>  
        </h:panelGrid>  
        <h:panelGroup>
        <h:panelGrid columns="1">
        <h:panelGrid id="pgFormaPagamento" columns="3" styleClass="outputLabel">
        	<h:outputLabel value="Código" styleClass="outputLabel"/>  
            <h:outputLabel value="Forma de Pagamento" style="font-size:14px; float:left"/> 
            <h:outputLabel  />            
            <p:inputText value="#{condicaoPagamentoBean.condicaoPagamento.formaPagamento.idFormaPagamento}" styleClass="inputId">
            	<p:ajax  listener="#{condicaoPagamentoBean.onChangeFormaPagamento}" update="pgFormaPagamento" />
            </p:inputText> 
            <p:inputText  value="#{condicaoPagamentoBean.condicaoPagamento.formaPagamento.descricao}" maxlength="40" styleClass="inputDescricao"> 
            	<p:ajax  listener="#{condicaoPagamentoBean.onChangeFormaPagamentoNull}" update="pgFormaPagamento" />
			</p:inputText>   
			<p:commandButton icon="ui-icon-search" actionListener="#{condicaoPagamentoBean.openDialogConsultarFormaPagamento}" ajax="true" style="margin-left:0px" styleClass="commandButton" immediate="true"/>
        </h:panelGrid>
        
        <h:panelGrid id="pgParcela" columns="5" style="margin-right:10%;">  
            <h:outputLabel value="Parcela" styleClass="outputLabel"/>  
            <h:outputLabel value="Prazo(dias)*" styleClass="outputLabel"/>   
            <h:outputLabel value="Percentual*" styleClass="outputLabel"/>   
            <h:outputLabel  />
            <h:outputLabel  />
            <p:inputText  value="#{condicaoPagamentoBean.parcela.numero}" styleClass="inputId" disabled="true" />  
  			<p:inputText value="#{condicaoPagamentoBean.parcela.dias}" styleClass="inputId" maxlength="6" style="width:70px" >
  				<f:convertNumber type="number"/>
  			</p:inputText>   
  			<p:inputText  value="#{condicaoPagamentoBean.parcela.percentual}" maxlength="6" styleClass="inputId" style="width:70px">
  				<f:convertNumber type="number"/>
  			</p:inputText>   
  			<p:commandButton icon="ui-icon-circle-plus" action="#{condicaoPagamentoBean.addParcela}" 
  								update="pgCondicaoPagamento, pgParcela, messagesManterCondPgto"/>
  			<p:commandButton value="Limpar" action="#{condicaoPagamentoBean.clean}" update="tableParcela" immediate="true"/>
        </h:panelGrid> 
        </h:panelGrid>
        </h:panelGroup>
        <p:dataTable  id="tableParcela" value="#{condicaoPagamentoBean.dmParcela}" var="parcela" style="margin-top:30px; width:30%"  
        				rowKey="#{parcela.idParcela}" selection="#{condicaoPagamentoBean.parcelaSelect}" >
			<p:column style="text-align:center">
				<f:facet name="header">
					<h:outputText value="Parcela" />
				</f:facet>
				<h:outputText value="#{parcela.numero}" />
			</p:column>
			<p:column style="text-align:center">
				<f:facet name="header">
					<h:outputText value="Prazo" />
				</f:facet>
				<h:outputText value="#{parcela.dias}" />
			</p:column>
			<p:column style="text-align:center">
				<f:facet name="header">
					<h:outputText value="Percentual" />
				</f:facet>
				<h:outputText value="#{parcela.percentual}" />
			</p:column>
       	 	<f:facet name="footer" >
       	 		<h:outputText value="Total = #{condicaoPagamentoBean.totalParcela}%" >
       	 			<f:convertNumber maxFractionDigits="2" minFractionDigits="2"/>
       	 		</h:outputText>
       	 	</f:facet>        
        </p:dataTable>
    </p:panel>  
    <p:commandButton value="Salvar" action="#{condicaoPagamentoBean.saveCondicaoPagamento}" update="panelManterCondicaoPagamento" styleClass="commandButton" /> 
	<p:commandButton value="Voltar" action="#{condicaoPagamentoBean.consultarCondicaoPagamento}" immediate="true" styleClass="commandButton" /> 
</h:form>  	
<ui:include src="/view/condicaoPagamento/dialogConsultarFormaPagamento.xhtml"></ui:include>
</ui:define>
</ui:composition>
